Attribute VB_Name = "MEntryPoints"
''' VBA Code Documentor 5.0 by Rob Bovey, copyright 1996-2004,
''' all rights reserved. May be redistributed for free,
''' but may not be sold without the author's explicit permission.
Option Explicit


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Comments:   This is the entry point for the VBA Code Documentor.
'''
''' Date        Developer           Action
''' --------------------------------------------------------------------------
''' 01/10/00    Rob Bovey           Created
''' 06/09/04    Rob Bovey           Added the ability to operate on any open
'''                                 workbook by selecting it from the FProjects
'''                                 UserForm.
'''
Public Sub CodeDocumentorMain()
    
    Dim bUserCancel As Boolean
    Dim bProjProtect As Boolean
    Dim frmProjects As FProjects
    Dim lCalcMode As Long
    Dim wkbTarget As Excel.Workbook
    Dim wkbReportBook As Excel.Workbook
    Dim wksDetail As Excel.Worksheet
    Dim wksSummary As Excel.Worksheet
    
    On Error Resume Next
        ''' Recalc book list on data sheet.
        wksProgramData.Names(gszRNG_OPEN_BOOKS).Delete
        wksProgramData.Names.Add wksProgramData.Name & gszBANG & gszRNG_OPEN_BOOKS, "=DOCUMENTS(3)"
    If gbDEBUG_MODE Then
        On Error GoTo 0
    Else
        On Error GoTo ErrorHandler
    End If
    
    ''' Initialize global application variables.
    InitGlobals
    
    ''' Check for VBProject protection if the Excel version requires it.
    bProjProtect = False
    If Val(Application.Version) >= 10 Then
        bProjProtect = bIsProjectProtected()
    End If
    
    If Not bProjProtect Then
    
        ''' Display the form that allows the user to
        ''' select the project to document.
        Set frmProjects = New FProjects
        Load frmProjects
        If Not frmProjects.Initialize() Then
            Unload frmProjects
            Set frmProjects = Nothing
            Err.Raise glHANDLED_ERROR, , gszERR_NO_PROJECTS
        End If
        frmProjects.Show
        bUserCancel = frmProjects.UserCancel
        If Not bUserCancel Then Set wkbTarget = frmProjects.Book
        Unload frmProjects
        Set frmProjects = Nothing
        
        Application.ScreenUpdating = False
        Application.ScreenUpdating = True
        
        If Not bUserCancel Then
            
            If Application.ActiveWorkbook Is Nothing Then ThisWorkbook.Activate
            lCalcMode = Application.Calculation
            
            Application.Calculation = xlCalculationManual
            Application.ScreenUpdating = False
            Application.DisplayAlerts = False
        
            ''' Store the name of the workbook we're documenting.
            guProjectInfo.szBookName = wkbTarget.Name
            
            ''' Create the report workbook.
            Application.StatusBar = gszSTATUS_CREATING_REPORT
            If Not bCreateReportWorkbook(wkbReportBook, wksDetail, wksSummary) Then Err.Raise glHANDLED_ERROR
            
            ''' Enumerate the project.
            If Not bEnumerateComponents(wkbTarget, wksDetail) Then Err.Raise glHANDLED_ERROR
            
            ''' Create the summary report.
            Application.StatusBar = gszSTATUS_REPORT_GENERATOR
            If Not bSummaryReportGenerator(wksSummary) Then Err.Raise glHANDLED_ERROR
            
            ''' Roll up the procedure outline.
            wksDetail.Outline.ShowLevels RowLevels:=1
            
            ''' Save the report workbook.
            Application.StatusBar = gszSTATUS_SAVING_REPORT
            If Not bSaveReportWorkbook(wkbTarget, wkbReportBook) Then Err.Raise glHANDLED_ERROR
            
            ResetAppProperties lCalcMode
            wkbReportBook.Saved = True
        
        End If  ''' If Not bUserCancel Then
        
    Else
        MsgBox gszERR_VBPROJ_PROTECT, vbExclamation, gszAPP_TITLE
    End If      ''' Else block for: If bIsProjectProtected() Then
    
    Exit Sub
    
ErrorHandler:
    If Len(gszErrMsg) = 0 Then gszErrMsg = Err.Description & " (CodeDocumentorMain)"
    ResetAppProperties
    MsgBox gszErrMsg, vbCritical, gszAPP_TITLE
End Sub
